package cn.com.flower.admin.content.controller;

import cn.com.flower.admin.content.pojo.param.CategoryAddNewParam;
import cn.com.flower.admin.content.service.ICategoryService;
import cn.com.flower.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
@Slf4j
@Api(tags = "1.类别管理")
@RestController
@RequestMapping("/categories")
public class CategoryController {


    @Autowired
    private ICategoryService categoryService;


    @PostMapping("/add-new")
    @ApiOperation("添加类别")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid CategoryAddNewParam categoryAddNewParam) {
        log.debug("开始执行【添加类别】的请求，参数：{}",categoryAddNewParam);
        categoryService.AddNew(categoryAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据id删除类别")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "类别id",required = true,dataType = "long")
    })
    public JsonResult delete(@PathVariable @Range(min = 1,message = "请提交有效的类别id值!")Long id){
        log.debug("开始执行【根据id删除类别】的请求，参数：{}",id);
        categoryService.delete(id);
        return JsonResult.ok();
    }

}
